<html>
	<head>
		<meta charset="utf-8">
		<title>喵~</title>
		<link rel="stylesheet" type="text/css" href="../style.css">
	</head>
	<body>
		<h1>评论区（临时？）</h1>
		<script>
			function setCookie(cname,cvalue,exdays){
				var d = new Date();
				d.setTime(d.getTime()+(exdays*24*60*60*1000));
				var expires = "expires="+d.toGMTString();
				document.cookie = cname+"="+cvalue+"; "+expires;
			}
			function getCookie(cname){
				var name = cname + "=";
				var ca = document.cookie.split(';');
				for(var i=0; i<ca.length; i++) {
					var c = ca[i].trim();
					if (c.indexOf(name)==0) { return c.substring(name.length,c.length); }
				}
				return "";
			} // from https://www.runoob.com/js/js-cookies.html
			function s_commit(content, repo) {
				if (document.getElementById('token').value == '') window.alert('access_token为空，请先获取access_token');
				else if (content != '') {
					setCookie('acctok', document.getElementById('token').value, 1);
					document.body.innerHTML += `<p>${content}</p>`;
				}
			}
			function r_commit(repository) {
				// 由于gitee给的api不可用，于是乎我去翻html然后找到了这个。
				// https://gitee.com/owner/repo/comment_list
				/*var req = new XMLHttpRequest();
				req.open('GET', `https://gitee.com/${repository}/comment_list`, true); // false -> 同步, true -> 异步
				req.send();
				req.onreadystatechange = () => {
					if (req.readyState == 4 && req.status == 200) {
						var resp = JSON.parse(req.responseText);
						document.body.innerHTML += `${resp}`;
					}
				}*/
				if (JSONP_data["comments_count"] <= 0) {
					document.write("<p>暂无评论</p>");
				} else {
					// document.write(JSONP_data["html"]);

				}
			}
		</script>
		<br />
		<input type="text" id="token" placeholder="access_token">
		<script>
			var tok = getCookie("acctok");
			if (tok != '') {
				document.getElementById('token').value = tok;
			}
		</script>
		<a href="code.html">获取access_token</a><br /><br />
		<input type="text" id="msg">
		<input type="button" value="评论" onclick="s_commit(document.getElementById('msg').value, 'cat_planet/cat_planet')">
		<br /><h3>评论区</h3>
		<script>r_commit('cat_planet/cat_planet');</script>
	</body>
</html>
